package com.itheima.udpqunliao;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;

/*
udp  组播 群聊 接收端
 */
public class ReceiveClient {

    public static void main(String[] args) throws IOException {
        //创建接受对象
        MulticastSocket ms = new MulticastSocket(10086);
        //加入到群聊中
        InetAddress zubo = InetAddress.getByName("224.0.1.0");
        ms.joinGroup(zubo);
        //创建数据对象
        byte[] bytes = new byte[1024 * 64];
        DatagramPacket dp = new DatagramPacket(bytes, bytes.length);

        //接受
        ms.receive(dp);
        //展示数据
        int length = dp.getLength();
        String s = new String(bytes, 0, length);
        System.out.println(s);
        //释放资源
        ms.close();

    }
}
